package com.bite.system.manager;

import com.bite.common.core.contants.CacheConstants;
import com.bite.redis.config.RedisService;
import com.bite.system.domain.exam.Exam;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;


@Component
public class ExamCacheManager {


    @Autowired
    private RedisService redisService;


    /**
     * 在未完成的列表放
     * 在基本信息放
     * @param exam
     */
    public void addCache(Exam exam) {
        redisService.leftPushForList(getExamListKey(), exam.getExamId());  //未完赛
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);  //竞赛详情
    }

    public void deleteCache(Long examId) {
        redisService.removeForList(getExamListKey(), examId);
        redisService.deleteObject(getDetailKey(examId));
        redisService.deleteObject(getExamQuestionListKey(examId));
    }

    private String getExamListKey() {
        return CacheConstants.EXAM_UNFINISHED_LIST;
    }

    private String getDetailKey(Long examId) {
        return CacheConstants.EXAM_DETAIL + examId;
    }

    private String getExamQuestionListKey(Long examId){
        return CacheConstants.EXAM_QUESTION_LIST + examId;
    }



}
